﻿@using Presentation.Web.Admin
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Ajax.BeginForm("add", "advertise", new AjaxOptions
{
    HttpMethod = "post",
    OnBegin = "checkedAddForm",
    OnFailure = "addFailure",
    OnSuccess = "addSuccess"
}))
{  
    <fieldset class="module width_full">
        @Html.Partial("_AddForm")
    </fieldset>
    <p>
        @{
    if (Html.HasUiPermission(this.ViewContext, "add"))
    { 
            <input type="submit" value="添加" class="alt_btn module_margin" />
    }
        }
    </p>
}
<script type="text/javascript">

    function checkedAddForm() {
        var res = true;
        if ($('#Name').val() == "") {
            alert("广告名不能为空");
            $('#Name').focus();
            res = false;
            return res;
        }
        if ($('#Remark').val() == "") {
            alert("描述不能为空");
            $('#Remark').focus();
            res = false;
            return res;
        }
        if ($('#Url').val() == "") {
            alert("链接地址不能为空");
            $('#Url').focus();
            res = false;
            return res;
        }
        else {
            var url = $('#Url').val();
            url = url.toLowerCase();
            if (url.indexOf('http://') < 0) {
                alert("链接地址必须以http://开头");
                $('#Url').focus();
                res = false;
                return res;
            }
        }
        return res;
    }

    function addSuccess(res) {
        if (res.success) {
            alert("添加成功");
            window.location.reload();
        }
        else {
            alert(res.message);
        }
    }

    function addFailure() {
        alert("添加失败了T_T！");
    }
</script>
